﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RFS.BizLogic.Sys.impl;
using RFS.Domain.Sys;

namespace ProtoWinform
{
    public partial class FrmLogin : Form
    {
        List<User> _users = new List<User>();

        private IConfigT _config;
        public FrmLogin()
        {
            InitializeComponent();
            
            _config= AntiObject.Ins.Get<IConfigT>() ;
            _users= AntiObject.Ins.Get<IConfigT>().ConfigSys.Users??new List<User>();
            msg.Text = "";

        }

        public User User { get; set; }

        private void bok_Click(object sender, EventArgs e)
        {
            if (tacc.Text == "admin" && _config.ConfigSys.DelPwd == tpwd.Text )
            {
                // pass
                this.User = new User()
                {
                    Name = "admin",
                    Pwd = "admin",
                    NameCn = "admin"
                };
            }
            else  
            {


                var u = _users.FirstOrDefault(x =>
                {
                    return x.Name == tacc.Text && x.Pwd == tpwd.Text;
                });
                if (u == null)
                {

                    msg.Text = "账号无效";
                    return;
                }

                 User = u;
            }



            DialogResult = DialogResult.OK;
            Close();
        }

        private void bcancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;

        }

        private void tpwd_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                bok_Click(null, null);

            }
        }
    }
}
